package com.sgcc.dlsc.redis.demo.controller;

import com.sgcc.comm.util.ResultUtil;
import com.sgcc.dlsc.redis.demo.service.RedisServerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: 李孟帅
 * @CreateTime: 2019-10-31 08:49
 * @Description: ${Description}
 */
@RequestMapping("/redisClient")
@RestController
@CrossOrigin(maxAge = 3600)
@Api("基于redis的内存数据库访问相关的文档")
public class RedisServerController {
    @Resource
    private RedisServerService redisServerService;

    @GetMapping("/addString")
    @ApiOperation("添加String类型的值")
    public ResultUtil addKey(@RequestParam(value = "key") String key,
                          @RequestParam(value = "value") String value) {
        return redisServerService.addKey(key, value);
    }

    @GetMapping("/queryString")
    @ApiOperation("根据key查询String类型的值")
    public ResultUtil queryKey( @RequestParam(value = "key")String key) {
        return redisServerService.queryKey( key);
    }
    @GetMapping("/deleteString")
    @ApiOperation("根据key删除String类型的值")
    public ResultUtil deleteKey( @RequestParam(value = "key")String key) {
        return redisServerService.deleteKey( key);
    }
    @GetMapping("/updateString")
    @ApiOperation("根据key修改String类型的值")
    public ResultUtil updateKey( @RequestParam(value = "key")String key,
                         @RequestParam(value = "value") String value) {
        return redisServerService.updateKey( key,value);
    }

    @GetMapping("/queryAll")
    @ApiOperation("查询所有的key")
    public ResultUtil queryAll(){
        return redisServerService.queryAll();
    }
}
